package com.ayu.shortlink.engine.controller;

import com.ayu.shortlink.engine.common.convention.result.Result;
import com.ayu.shortlink.engine.common.convention.result.Results;
import com.ayu.shortlink.engine.dao.entity.CouponTemplateDO;
import com.ayu.shortlink.engine.service.CouponTemplateService;
import lombok.RequiredArgsConstructor;
import org.apache.ibatis.annotations.Param;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequiredArgsConstructor
public class CouponTemplateController {
    private final CouponTemplateService couponTemplateService;

    /**
     * 根据条件查找优惠券模版
     */
    @GetMapping("/api/short-link/engine/v1/coupon-template/find")
    public Result<List<CouponTemplateDO>> findCouponTemplate(@Param("couponTemplateIds")List<Long> couponTemplateIds, @Param("shopNumberIds") List<Long> shopNumberIds){
        return Results.success(couponTemplateService.findCouponTemplate(couponTemplateIds,shopNumberIds));
    }

    /**
     * 根据 ID 和 ShopNumber 查询具体的优惠券模版信息
     */
    @GetMapping("/api/short-link/engine/v1/coupon-template/shopNumber/find")
    public Result<CouponTemplateDO> findCouponTemplateByIdAndShopNumber(String shopNumber, String couponTemplateId){
        return Results.success(couponTemplateService.findCouponTemplateByIdAndShopNumber(shopNumber,couponTemplateId));
    }

    /**
     * 获取优惠券排行榜
     */
    @GetMapping("/api/short-link/engine/v1/coupon-template/hot-rank/{n}")
    public Result<List<CouponTemplateDO>> findHotRank(@PathVariable("n") Integer n){
        return Results.success(couponTemplateService.findHotRank(n));
    }
}
